package com.kingyea.mobilepolice.zuul.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;


/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description 自定义业务异常类，用于捕获异常信息
 * @date Created in 2017/12/28 14:22
 */
public class BusinessException extends RuntimeException implements Serializable {
    private static final Logger logger = LoggerFactory.getLogger(BusinessException.class);

    private String code; //错误码

    private String msg; //错误信息

    private Object obj; //捕获异常错误后所返回的对象

    BusinessException() {

    }


    public BusinessException(String code) {
        this.code = code;
        this.msg = StateCode.getMsg(code);
    }

    public BusinessException(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BusinessException(String code, String msg, Object obj) {
        this.code = code;
        this.msg = msg;
        this.obj = obj;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getObj() {
        return obj;
    }

    public void setObj(Object obj) {
        this.obj = obj;
    }

    @Override
    public void printStackTrace() {
        logger.error("BusinessException:" + this.msg);
        System.err.println("BusinessException:  code: " + this.code + " msg: " + this.msg);
        super.printStackTrace();
    }

}
